home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / fpkpas92.zip / SRCRTL.ZIP / RTL / DOS / IMAGE.PPI < prev    next >
Text File  |  1997-07-01  |  6KB  |  177 lines

  1. { FILE: IMAGE.INC zu GRAPH.PP }    
  2.  
  3. procedure GetImage(x1,y1,x2,y2 : integer;var BitMap);
  4.  
  5. var
  6.   i,linesize,target  : longint;
  7.   ofs1,ofs2,bank1,bank2,diff : longint;
  8. begin
  9.   _graphresult:=grOk;
  10.   if not isgraphmode then
  11.   begin
  12.     _graphresult:=grnoinitgraph;
  13.     exit;
  14.   end;         
  15.  
  16. x1:=x1+aktviewport.x1;
  17. y1:=y1+aktviewport.y1;
  18. x2:=x2+aktviewport.x1;
  19. y2:=y2+aktviewport.y1;        
  20.  
  21. if (x1>_maxx) or (y1>_maxy) or (x2<0) or (y2<0) then exit;       
  22.  
  23. target:=longint(@bitmap)+4;
  24. pinteger(@bitmap)^:=x2-x1+1;
  25. pinteger(@bitmap+2)^:=y2-y1+1; 
  26. linesize:=(x2-x1+1)*BytesPerPixel;
  27.  
  28. for i:=y1 to y2 do
  29.   begin
  30.     ofs1:=Y_ARRAY[i]+X_ARRAY[x1];
  31.     ofs2:=Y_ARRAY[i]+X_ARRAY[x2];
  32.     bank1:=ofs1 shr WinShift;
  33.     bank2:=ofs2 shr WinShift;  
  34.     if bank1 <> AW_BANK then 
  35.       begin
  36.         Switchbank(bank1);
  37.         AW_BANK:=bank1;
  38.       end;
  39.     if bank1=bank2 
  40.       then ScreenToMem(ofs1 and WinLoMask,target,linesize)
  41.       else begin     
  42.         diff:=(bank2 shl winshift)-ofs2;
  43.         ScreenToMem(ofs1 and WinLoMask,target,diff-BytesPerPixel);
  44.         Switchbank(bank2);
  45.         AW_BANK:=bank2;
  46.         ScreenToMem((ofs1+diff) and WinLoMask,target+diff,linesize-diff);
  47.       end; 
  48.     target:=target+linesize;
  49.   end;
  50. end;
  51.  
  52. procedure PutImage(x,y : integer;var BitMap;BitBlt : word);
  53.  
  54.       var
  55.          height,width : integer;
  56.          diff         : integer;
  57.          increment,i  : longint;
  58.          source,o1,o2 : longint;
  59.          offset       : longint;
  60.          viewport     : viewporttype;
  61.       begin
  62.          _graphresult:=grOk;
  63.          if not isgraphmode then
  64.            begin
  65.               _graphresult:=grnoinitgraph;
  66.               exit;
  67.            end;
  68.          
  69.          source:=longint(@bitmap)+4;
  70.          Width:=pinteger(@bitmap)^;
  71.          Increment:=longint(Width);
  72.          height:=pinteger(@bitmap+2)^;
  73.          { wenn ausserhalb des Screens Procedur verlassen }
  74.          x:=x+aktviewport.x1;
  75.          y:=y+aktviewport.y1;
  76.          
  77.          if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen; 
  78.          if (x > viewport.x2 ) or 
  79.              (y > viewport.y2 ) or 
  80.               (x+Increment < viewport.x1) or 
  81.                (y+height < viewport.y1) then exit;
  82.   
  83.            { Clip oben }
  84.            if y < viewport.y1 then 
  85.              begin
  86.                diff:=viewport.y1-y;
  87.                height:=height-diff;
  88.                source:=source+Increment*diff;
  89.                y:=viewport.y1;
  90.              end;
  91.            { Clip unten }
  92.            
  93.            if y+height > viewport.y2 then 
  94.                height:=viewport.y2-y;
  95.            
  96.            { Clip links }
  97.            if x < viewport.x1 then 
  98.              begin
  99.                diff:=viewport.x1-x;
  100.                Width:=Increment-diff;
  101.                source:=source+diff;
  102.                x:=viewport.x1;
  103.              end;
  104.            
  105.            { clip rechts }
  106.            if x+width > viewport.x2 then 
  107.              begin
  108.                diff:=x+width-viewport.x2;
  109.                Width:=Increment-diff;
  110.              end;
  111.           
  112.  Increment:=Increment*BytesPerPixel;
  113.  Width:=Width*BytesPerPixel;  
  114.  for i:=y to y+height-1 do
  115.    begin
  116.      offset:=Y_ARRAY[i] + X_ARRAY[x];
  117.      o1:=offset shr winshift;
  118.      o2:=( offset + width ) shr winshift;
  119.      if o1 <> AW_BANK then 
  120.        begin
  121.          Switchbank(o1);
  122.          AW_BANK:=o1;
  123.        end;
  124.      if o1 = o2 then
  125.      begin  
  126.        case bitblt of
  127.          normalput : MemToScreen (source,offset and WinLoMask,width);
  128.          andput    : MemAndScreen(source,offset and WinLoMask,width);
  129.          orput     : MemOrScreen (source,offset and WinLoMask,width);
  130.          xorput    : MemXorScreen(source,offset and WinLoMask,width);
  131.          notput    : MemXorScreen(source,offset and WinLoMask,width);
  132.        end;
  133.      end else begin
  134.      { Bankswitching }
  135.        diff:=((o2 shl winshift)-offset);
  136.        case bitblt of
  137.          normalput : begin
  138.                       MemToScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  139.                       Switchbank(o2); AW_BANK:=o2;
  140.                       MemToScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  141.                      end;
  142.          andput    : begin
  143.                       MemAndScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  144.                       Switchbank(o2); AW_BANK:=o2;
  145.                       MemAndScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  146.                      end;
  147.          orput     : begin
  148.                       MemOrScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  149.                       Switchbank(o2); AW_BANK:=o2;
  150.                       MemOrScreen (source++diff,(offset+diff) and WinLoMask,width-diff);
  151.                      end;
  152.          xorput    : begin
  153.                       MemXorScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  154.                       Switchbank(o2); AW_BANK:=o2;
  155.                       MemXorScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  156.                      end;
  157.          notput    : begin
  158.                       MemNotScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  159.                       Switchbank(o2); AW_BANK:=o2;
  160.                       MemNotScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  161.                      end;
  162.        end; { case }
  163.      end; { else }
  164.      source:=source+Increment;
  165.  end; { for i }
  166. end;
  167.     
  168.     
  169.     function ImageSize(x1,y1,x2,y2 : integer) : word;
  170.  
  171.       begin
  172.          _graphresult:=grOk;
  173.          ImageSize:=(x2-x1+1)*(y2-y1+1)*BytesPerPixel+4;
  174.          { +4, da Breite und Höhe mit abgespeichert werden }
  175.       end;
  176.  
  177.